<template>
	<view>
		<!-- 题库练习 -->
		<u-navbar title="题库练习" title-color="#fff" :background="background" back-icon-color="#ffffff"
			:back-text-style="{color: '#fff'}">
			<view class="slot-wrap">
				<!-- <u-icon name="list-dot" color="#ffffff" size="36" @click="changeModel"></u-icon> -->
			</view>
		</u-navbar>
		<u-search class="searchBar" placeholder="搜索题库" v-model="keyword" :clearabled="true" @search="searchFunc"
			@custom="searchFunc" :show-action="true"></u-search>
		<view class="bankArea">
			<prac-bank v-for="(item,index) in bankList" :key="index" :bankItem="item"></prac-bank>
		</view>
		<u-loadmore :status="status" />
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import store from '@/store/index.js'; //需要引入store
	export default {
		data() {
			return {
				keyword: '',
				bankList: [],
				status: 'loadmore',
				page: 1,
				background: {
					'background-image': 'linear-gradient(45deg, #007fd1, #013cd2)'
				},
			}
		},
		methods: {
			searchFunc(keyword) {
				console.log(keyword);
				var that = this
				this.$api.getBank(1, keyword)
					.then(res => {
						uni.showToast({
							title: '搜索成功'
						})
						console.log(res);
						// console.log('考试列表:',res.values.records);
						that.bankList = res.values.records
					})
			},
		},
		onLoad() {
			// 获取题库列表
			this.$api.getBank(1, '')
				.then(res => {
					console.log(res.values.records);
					this.bankList = res.values.records
					return res.values.records
				})
				.then(res => {
					console.log("接收到：", res);
				})
		},
		onReachBottom() {
			if (this.keyword == undefined) {
				this.keyword = ''
			}
			if (this.status === 'loadmore') {
				this.page += 1
				this.status = 'loading'
				this.$api.getBank(this.page, this.keyword)
					.then(res => {
						if (res.values.records.length === 0) {
							this.status = 'nomore'
						} else {
							this.bankList = this.bankList.concat(res.values.records)
							this.status = 'loadmore'
						}
					})
			}
		}

	}
</script>

<style>
	.searchBar {
		padding: 20upx;
	}

	.bankArea {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;

	}
</style>
